package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"weather_mcp_service/weather"
)

func main() {
	// 初始化 Gin 框架
	r := gin.Default()

	// 定义获取天气的路由
	r.GET("/weather", func(c *gin.Context) {
		// 获取用户传入的 location 参数
		location := c.Query("location")
		if location == "" {
			c.JSON(http.StatusBadRequest, gin.H{"error": "缺少 location 参数"})
			return
		}

		// 调用天气服务获取实时天气
		weatherData, err := weather.GetRealTimeWeather(location)
		if err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
			return
		}

		c.JSON(http.StatusOK, weatherData)
	})

	// 启动服务
	r.Run(":8080")
}